package com.springbootblog.controller.fontend;

import com.springbootblog.service.fontend.ArticleService;
import com.springbootblog.utils.Email;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

/**
 * 文章部分接口
 * @className AboutController
 * @author camellia
 * @email 805795955@qq.com
 * @date 2024/01/01
 * @version 1.0
 */
@RequestMapping("java")
@RestController
//@CrossOrigin(origins="*",maxAge=3600)
public class ArticleController
{
    // 自动装载（dao接口注入）
    @Autowired
    private ArticleService articleService;

    /*public ArticleController(HttpServletRequest request) {
        super(request);
    }//*/

    /**
     * 文章详情
     * @param article_id
     * @param request
     * @return
     * @throws Exception
     */
    @GetMapping("article/getArticleDetail")
    public Map<String, Object> getArticleDetail(@RequestParam(defaultValue = "") String article_id, HttpServletRequest request) throws Exception
    {
        Map<String, Object> result = articleService.getArticleDetail(article_id,request);
        return result;
    }

    /**
     * 提交评论
     * @param article_id 文章id
     * @param email 邮箱
     * @param content 评论内容
     * @param content_reply 回复内容
     * @param replyid 回复评论id
     * @param request 请求对象
     * @Response code 操作状态
     * @Response msg 返回语
     * @throws Exception
     */
    @GetMapping("article/putComment")
    public Map<String, Object> putComment(@RequestParam(defaultValue = "") String article_id, @RequestParam(defaultValue = "") String email, @RequestParam(defaultValue = "") String content, @RequestParam(defaultValue = "") String content_reply,@RequestParam(defaultValue = "") String replyid,HttpServletRequest request) throws Exception
    {
        Map<String, Object> result = articleService.putComment(article_id,email,content,content_reply,replyid,request);
        return result;
    }

    @Autowired
    private Email email;

    /**
     * 测试邮件发送
     * @return
     * @throws Exception
     */
    @GetMapping("article/testMail")
    public Map<String, Object> testMail() throws Exception
    {
        email.sendSimpleMail("805795955@qq.com","测试邮件","成功了嘛？");
        return null;
    }





}
